package com.fafu.rbac.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.fafu.common.web.bean.PageBean;
import com.fafu.common.web.bean.Result;
import com.fafu.common.web.bean.ResultUtil;
import com.fafu.common.web.controller.BaseController;
import com.fafu.common.web.mybatis.QueryWrapperUtil;
import com.fafu.rbac.conterter.PermissionConverter;
import com.fafu.rbac.domain.entity.Permission;
import com.fafu.rbac.domain.query.PermissionQuery;
import com.fafu.rbac.domain.vo.PermissionVO;
import com.fafu.rbac.service.PermissionService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/permission")
public class PermissionController extends BaseController<Permission> {
    @Resource
    private PermissionService permissionService;

    public PermissionController(IService<Permission> service) {
        super(service);
    }

    @PostMapping("/list")
    public Result list(@RequestBody PermissionQuery permissionQuery){
        IPage<Permission> page = new Page<>(permissionQuery.getPageNum(),permissionQuery.getPageSize());
        Wrapper<Permission> queryWrapper = QueryWrapperUtil.build(permissionQuery);
        permissionService.page(page,queryWrapper);

        PageBean<Permission> pageBean = PageBean.init(page);
        PageBean<PermissionVO> permissionVOPageBean = new PermissionConverter().entityPageBean2VOPageBean(pageBean);
        return ResultUtil.success().addData("pageBean",permissionVOPageBean);
    }
}
